﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web.BusinessInformation.Example
{
    public partial class GridView_Ex : System.Web.UI.Page
    {
         private static DataTable dt;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (dt == null)
            {
                dt = CreateTable();
            }
            gvTest.DataSource = dt;
            gvTest.DataBind();
        }

        private DataTable CreateTable()
        {
            
            DataTable dt2 = new DataTable();
            dt2.Columns.Add(new DataColumn("用户号", Type.GetType("System.String")));
            dt2.Columns.Add(new DataColumn("用户名", Type.GetType("System.String")));

            dt2.Columns.Add(new DataColumn("初开金额", Type.GetType("System.Double")));
            dt2.Columns.Add(new DataColumn("实收金额", Type.GetType("System.Double")));
            dt2.Columns.Add(new DataColumn("核销金额", Type.GetType("System.Double")));
            dt2.Columns.Add(new DataColumn("欠费", Type.GetType("System.Double")));

            dt2.Columns.Add(new DataColumn("回收率（%）", Type.GetType("System.String")));
            dt2.Columns.Add(new DataColumn("实收/应收", Type.GetType("System.String")));

            DataRow dr3 = dt2.NewRow();
            dr3["用户号"] = "0100942";
            dr3["用户名"] = "康达印染服装公司";

            dr3["初开金额"] = "230.2";
            dr3["实收金额"] = "512";
            dr3["核销金额"] = "110";
            dr3["欠费"] = "52.32";

            dr3["回收率（%）"] = ".00";
            dr3["实收/应收"] = ".00";
            dt2.Rows.Add(dr3);


            DataRow dr = dt2.NewRow();
            dr["用户号"] = "0100943";
            dr["用户名"] = "上海三槺计算机公司";

            dr["初开金额"] = "530.2";
            dr["实收金额"] = "812";
            dr["核销金额"] = "120";
            dr["欠费"] = "520.32";

            dr["回收率（%）"] = ".00";
            dr["实收/应收"] = ".00";
            dt2.Rows.Add(dr);

            Random ra=new Random();
            for (int i = 0; i < 30; i++)
            {

                DataRow dr4 = dt2.NewRow();
                dr4["用户号"] = "0100943";
                dr4["用户名"] = "上海三槺计算机公司";

                dr4["初开金额"] = ra.Next(10, 500);
                dr4["实收金额"] = ra.Next(10, 500);
                dr4["核销金额"] = ra.Next(10, 500);
                dr4["欠费"] = ra.Next(10, 500);

                dr4["回收率（%）"] = ".00";
                dr4["实收/应收"] = ".00";
                dt2.Rows.Add(dr4);

            }


            return dt2;
        }

        protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlType.SelectedValue == "1")
            {
                //gvTest.SettingsPager.Mode = DevExpress.Web.ASPxGridView.ShowPager;
                gvTest.SettingsPager.PageSize = Convert.ToInt32(txtPage.Text.Trim());
            }
            else
            {
                //gvTest.SettingsPager.Mode = DevExpress.Web.ASPxGridView.ShowAllRecords;
            }
            gvTest.DataSource = dt;
            gvTest.DataBind();
        }

        protected void chkQuery_CheckedChanged(object sender, EventArgs e)
        {
            if (chkQuery.Checked)
            {
               
                gvTest.Settings.ShowFilterRow = true;
            }
            else
            {
                gvTest.Settings.ShowFilterRow = false;
            }
        }
        protected void btnXlsExport_Click(object sender, EventArgs e)
        {
            gvTest.Settings.ShowFooter = false;
            gridExport.WriteXlsToResponse();
        }

        protected void gvTest_DataBinding(object sender, EventArgs e)
        {
        
         
        }

        protected void gvTest_DataBound(object sender, EventArgs e)
        {
           
        }

        protected void gvTest_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
        {
    
            if(e.RowType.ToString()=="Data")
            {
                if(e.Row.Cells.Count>0)
                {
                    var cell = (e.Row).Cells[0];
                    if (cell.Controls.Count >0)
                    {
                        foreach (Control control in cell.Controls)
                        {
                            var a = control.FindControl("textLable");
                            if (null != a)
                            {
                                a.FindControl("textLable").Visible = false;
                            }
                        } 
                    }  
                }
            }
         
        }
   
    }
 
}